package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService service;

    @RequestMapping("login")
    public  String login(String userName, String pwd, HttpServletRequest request){
        //调用业务方法完成登录查询
        UserBean user=service.login(userName,pwd);
        if (user !=null){
            //在会话范围内，绑定登录用户
            request.getSession().setAttribute("loginUser",user);

            return user.getLevel();
        }

        return "no";
    }
    @RequestMapping("getLoginUser")
    public  UserBean getLoginUser(HttpServletRequest request){//得到登录用户
       UserBean user= (UserBean) request.getSession().getAttribute("loginUser");
       return user;


    }
}
